package com.wnxy.controller;

import com.wnxy.entity.Goods;
import com.wnxy.log.SystemLog;
import com.wnxy.service.GoodsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("goods")
@Api("商品模块")
@CrossOrigin
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping
    //@Cacheable(value = "goods",key = "'list'")
    @SystemLog(value = "查询商品列表")
    public List<Goods> list(){
        List<Goods> list = goodsService.list();
        return list;
    }

    @PostMapping
    @CacheEvict(value = "goods",allEntries = true)
    @SystemLog(value = "添加或修改商品")
    public void saveOrUpdate(@RequestBody Goods goods){
        goodsService.saveOrUpdate(goods);
    }

    @DeleteMapping("{id}")
    @CacheEvict(value = "goods",allEntries = true)
    public void delete(@PathVariable("id")String id){
        goodsService.removeById(id);
    }

}
